package com.haotunet.app.goldtreasure.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.RedPacketInfo;
import com.haotunet.app.goldtreasure.views.TipPopupView;

import java.util.List;

/**
 * Created by lifeng on 2017/4/26.
 */

public class RedPacketAdapter extends HolderAdapter<RedPacketInfo, RedPacketAdapter.ViewHolder> {
    public RedPacketAdapter(Context context, List<RedPacketInfo> mlist) {
        super(context, mlist);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, RedPacketInfo redPacketInfo, int position) {
        return inflate(R.layout.item_gcoin_get_detail);
    }

    @Override
    public ViewHolder buildHolder(View convertView, RedPacketInfo redPacketInfo, int position) {
        RedPacketAdapter.ViewHolder holder = new RedPacketAdapter.ViewHolder();
        holder.tvAmount = (TextView) convertView.findViewById(R.id.tv_add_coins);
        holder.tvTime = (TextView) convertView.findViewById(R.id.tv_addcoin_time);
        holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_addcoin_type);
        holder.ivTip = (ImageView) convertView.findViewById(R.id.iv_red_packet_explain);
        return holder;
    }

    @Override
    public void bindViewDatas(View convertView, ViewHolder holder, RedPacketInfo redPacketInfo, int position) {
        if ("+".equals(redPacketInfo.getMoney().trim().substring(0, 1))) {
            holder.tvAmount.setTextColor(context.getResources().getColor(R.color.color_red));
        } else if ("-".equals(redPacketInfo.getMoney().trim().substring(0, 1))) {
            holder.tvAmount.setTextColor(context.getResources().getColor(R.color.color_green));
        } else {
            holder.tvAmount.setTextColor(context.getResources().getColor(R.color.color_black));
        }
        if (redPacketInfo.getShowTip()) {
            holder.ivTip.setVisibility(View.VISIBLE);
        } else {
            holder.ivTip.setVisibility(View.GONE);
        }
        holder.ivTip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new TipPopupView(context, null,context.getString(R.string.red_packet_using_explain), R.style.MyDialog)
                        .show();
            }
        });
        holder.tvAmount.setText(redPacketInfo.getMoney());
        holder.tvTime.setText(redPacketInfo.getCreateTime());
        holder.tvTitle.setText(redPacketInfo.getTitle());
    }

    public static class ViewHolder {
        TextView tvTitle;
        TextView tvTime;
        TextView tvAmount;
        ImageView ivTip;
    }
}
